package com.letsgo;

import java.util.ArrayList;

/**
 * This interface to declare all the different functions of communication between the client and the server.
 * It can be implemented by several protocol.
 */
public interface Requester {
	/**
	 * it uses to take the current owner of the application
	 * @return an Player object of the current owner
	 * @see Player
	 * @see setOwner
	 */
	public Player getOwner();
	
	/**
	 * it uses to take the current owner of the application
	 * @param p is a Player object used to identify the current owner of the application
	 * @see Player
	 * @see setOwner
	 */
	public void setOwner(Player p);
	/**
	 * Creates an user on the server from a Player Object
	 * @param p is a Player object used to send informations to the server
	 * @throws RequesterMissingPwdException if the player's pwd is not filled
	 * @see Player
	 * @see listUsers
	 * @see inviteUser
	 */
	public void createUser(Player p) throws RequesterMissingPwdException;
	
	/**
	 * Returns the list of all users without the pwd field filled
	 *@param start is the starting sequence number to retrieve
	 * @param end is the ending sequence number to retrieve
	 * @param last if true retrieves only the last player (regardless the 2 previous parameters)
	 * @return an ArrayList<Player> filled with all the players found on the server
	 * @see Player
	 * @see createUser
	 * @see inviteUser
	 */
	public ArrayList<Player> listUsers(int start, int end, boolean last);
	
	/**
	 * Creates a game on the server with informations from the Game Object given
	 * @param g is the Game Object used to get informations about the game
	 * @throws RequesterUnauthorizedException if the application is not logged on the server
	 * @throws RequesterUnsupportedMediaTypeException if the server do not understand the protocol of the application
	 * @see Game
	 * @see listGames
	 */
	public void createGame(Game g) throws RequesterUnauthorizedException, RequesterUnsupportedMediaTypeException;
	
	/**
	 * Returns the list of all games found on the server
	 * @param start is the starting sequence number to retrieve
	 * @param end is the ending sequence number to retrieve
	 * @param last if true retrieves only the last movement in the history (regardless the 2 previous parameters)
	 * @return an ArrayList<Game> filled with the list of all games found on the server
	 * @see Game
	 * @see createGame
	 */
	public ArrayList<Game> listGames(int start, int end, boolean last);
	
	/**
	 * Authorizes other users to join the given game
	 * @param g game authorized to be joined
	 * @throws RequesterUnauthorizedException if the application is not logged on the server
	 * @throws RequesterNotFoundException if the game is not found
	 * @throws RequesterUnsupportedMediaTypeException if the server do not understand the protocol of the application
	 * @see Game
	 * @see listUsers
	 * @see createUser
	 */
	public void inviteUser(Game g) throws RequesterUnauthorizedException, RequesterNotFoundException, RequesterUnsupportedMediaTypeException;
	
	/**
	 * Adds the player sending this request to the given game
	 * @param g game to be joined by the player (application)
	 * @throws RequesterUnauthorizedException if the application is not logged on the server
	 * @throws RequesterNotFoundException if the game is not found
	 * @throws RequesterUnsupportedMediaTypeException if the server do not understand the protocol of the application
	 * @see Game
	 * @see inviteUser
	 * @see deleteGame
	 * @see retrieveGame
	 */
	public void joinGame(Game g) throws RequesterUnauthorizedException, RequesterNotFoundException, RequesterUnsupportedMediaTypeException;
	
	/**
	 * Deletes the given game from the server
	 * @param g is the Game to delete
	 * @throws RequesterUnauthorizedException if the application is not logged on the server
	 * @throws RequesterForbiddenException if the request sender is not the game's owner
	 * @throws RequesterNotFoundException if the game is not found
	 * @see Game
	 * @see inviteUser
	 * @see joinGame
	 * @see retrieveGame
	 */
	public void deleteGame(Game g) throws RequesterUnauthorizedException, RequesterForbiddenException, RequesterNotFoundException;
	
	/**
	 * Retrieves a game from the server, this function returns the same Game given in parameters but with the board filled 
	 * @param g is the game to retrieve the board
	 * @return a the same Game Object as the one given, but filled with the board of the game
	 * @throws RequesterNotFoundException if the game is not found
	 * @see Game
	 * @see inviteUser
	 * @see joinGame
	 * @see deleteGame
	 */
	public Game retrieveGame(Game g) throws RequesterNotFoundException ;
	
	/**
	 * Play a movement on the given game
	 * @param g the game to play the movement
	 * @param b the movement to play
	 * @throws RequesterUnauthorizedException if the application is not logged on the server
	 * @throws RequesterForbiddenException if the request sender is not the game's owner
	 * @throws RequesterNotFoundException if the game is not found
	 * @see Game
	 * @see BoardMovement
	 * @see moveHistory
	 * @see retrieveGame
	 * @see deleteGame
	 * @see joinGame
	 */
	public void playMove(Game g, BoardMovement b) throws RequesterUnauthorizedException, RequesterForbiddenException, RequesterNotFoundException;
	
	/**
	 * Retrieves an ArrayList of BoardMovement regarding the the parameters given. An interval can be retrieve from the 2 first parameters, and if the last parameter is true, only the last movement will be retrieve
	 * @param g is the game to retrieve the movement history
	 * @param start is the starting sequence number to retrieve
	 * @param end is the ending sequence number to retrieve
	 * @param last if true retrieves only the last movement in the history (regardless the 2 previous parameters)
	 * @return en ArrayList of BoardMovement regarding the parameters given
	 * @throws RequesterNotFoundException
	 * @see Game
	 * @see BoardMovement
	 * @see playMove
	 * @see retrieveGame
	 */
	public ArrayList<BoardMovement> moveHistory(Game g, int start, int end, boolean last) throws RequesterNotFoundException;
}

